package com.example.springboot01.service;


import com.example.springboot01.entity.UserInfo;
import com.example.springboot01.mapper.UserInfoMapper;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service //告诉spring框架，我这个类是可以自动实例化的。就是自动new一个对象的意思。
public class UserInfoSerivce {
    @Autowired
    private UserInfoMapper userInfoMapper;

    public boolean checkLogin(String userCode, String userPwd){
        boolean flag = false;
        UserInfo userInfo = null;
        userInfo = userInfoMapper.checkLogin(userCode, userPwd);
        //if (!userInfo.equals(null))
        if (userInfo != null)
            flag = true;
        return flag;
    }

    public UserInfo checkLoginR(String userCode, String userPwd){
    return  userInfoMapper.checkLogin(userCode, userPwd);
    }

    public List<UserInfo> qryUserList(String field_name, String field_value){
        List<UserInfo> user_list = new ArrayList<UserInfo>();
        user_list = userInfoMapper.qryUserList(field_name, field_value);

        return user_list;
    }
    public int insertAUser(UserInfo userInfo){
        return userInfoMapper.insertUser(userInfo);
    }

    public UserInfo getAUserInfo(String user_code){
        return userInfoMapper.getAUserInfo(user_code);
    }
    public int editUser(UserInfo userInfo){
        return userInfoMapper.editUser(userInfo);
    }
    public int deleteUserInfo(String user_code){
        return userInfoMapper.deleteUser(user_code);
    }
    public List<UserInfo> qryUserPageList(String field_name, String field_value,
                                          int start_page, int page_size){
        //先把当前页转换成数据库里面的当前行
        int current_pos = (start_page - 1) * page_size;
        return userInfoMapper.qryUserPageList(field_name, field_value,
                current_pos, page_size);
    }
}
